//
//  MainTabBar.swift
//  01sinablog
//
//  Created by ZhangZiang on 15/12/12.
//  Copyright © 2015年 ZhangZiang. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    //tabBar里包含了tabBarButton,UIImageView(高为0),backgroundView
    override func layoutSubviews() {
        super.layoutSubviews()
//        print(subviews)
        
        let w = self.bounds.width/5
        let h = self.bounds.height
        
        var index : CGFloat = 0
        
        for subview : UIView in subviews
        {
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!)
            {
//                print(subview)
                let x = w * index
                
                subview.frame = CGRectMake(x, 0, w, h)
                
                index += (index == 1) ? 2 : 1
                
            }
        }
        composeBtn.frame = CGRectMake(2*w, 0, w, h)
//        composeBtn.frame = CGRectOffset(CGRectMake(0, 0, w, h), 2*w, -5)
       
        
        
        addSubview(composeBtn)
    }

    //懒加载中间的加号
    lazy var composeBtn : UIButton = {
        let btn = UIButton()
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Selected)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Selected)
        
        return btn
    }()
}
